﻿<%@ Page Title="" Language="C#" MasterPageFile="~/TsSite.Master" AutoEventWireup="true" CodeBehind="ManageBookingLinkNotification.aspx.cs" Inherits="TireService.Web.View.AdminView.ManageBookingLinkNotification" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallbackPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1.Export, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView.Export" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxLoadingPanel" TagPrefix="dx" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <table cellpadding="0" cellspacing="2" border="0">
        <tr>
            <td>
                <img id="imgManageBookingLinkNotification" alt="" src="~/Images/Medium/businessman.png" runat="server" style="width: 32px; height: 32px" />
            </td>
            <td valign="middle">
                <h3><asp:Label ID="lblManageBookingLinkNotification" runat="server" Text="Udsendelse af booking link"></asp:Label></h3>
            </td>
        </tr>
    </table>

    <dx:ASPxLoadingPanel ID="LoadingPanel" Text="Vent venligst..." ClientInstanceName="LoadingPanel" runat="server" Modal="True">
    </dx:ASPxLoadingPanel>

    <!-- Javascript of action dropdown list -->
    <script language="javascript" type="text/javascript">

        function MethodClicked() {
            // Prepare input
            var StartDate = new Date(txtStartdate.GetValue());
            var stringStartDate = StartDate.getDate() + "-" + (1 + StartDate.getMonth()) + "-" + StartDate.getFullYear();
            var EndDate = new Date(txtEnddate.GetValue());
            var stringEndDate = EndDate.getDate() + "-" + (1 + EndDate.getMonth()) + "-" + EndDate.getFullYear();

            var input = stringStartDate + '|' + stringEndDate + '|' + ddlMethod.GetValue();

            gvCustomer.PerformCallback(input);
        }

        function SendBookingLinkEmail() {
            var answer = confirm("Udsend email med booking link til brugere i listen?")
            if (answer) {
                // Show loading panel
                LoadingPanel.Show();

                // Prepare input
                var StartDate = new Date(txtStartdate.GetValue());
                var stringStartDate = StartDate.getDate() + "-" + (1 + StartDate.getMonth()) + "-" + StartDate.getFullYear();
                var EndDate = new Date(txtEnddate.GetValue());
                var stringEndDate = EndDate.getDate() + "-" + (1 + EndDate.getMonth()) + "-" + EndDate.getFullYear();

                var input = stringStartDate + '|' + stringEndDate + '|' + ddlMethod.GetValue();

                callSendBookingLinkEmail.PerformCallback(input);
            }
        }

        // Function that runs when server side completed processing
        function OnCallbackSendBookingLinkEmailCompleted(s, e) {
            MethodClicked();

            LoadingPanel.Hide();

            alert('Emails afsendt');
        }

        // Function that return error in case callback to server failed
        function CallBackError(s, e) {
            LoadingPanel.Hide();
            
            alert('Fejl opstod: ' + e.message);
        }

    </script>

    <dx:ASPxCallback ID="callSendBookingLinkEmail" ClientInstanceName="callSendBookingLinkEmail" runat="server" OnCallback="callSendBookingLinkEmail_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackSendBookingLinkEmailCompleted" />
    </dx:ASPxCallback>

    <table border="0" cellspacing="0" cellpadding="5" width="100%">
        <tr>
            <td style="width:50px">
                <dx:ASPxLabel ID="lblPeriod" runat="server" Text="Periode">
                </dx:ASPxLabel>
            </td>
            <td style="width:150px">
                <dx:ASPxDateEdit ID="txtStartdate" ClientInstanceName="txtStartdate" runat="server">
                    <ValidationSettings CausesValidation="true" ValidationGroup="SelectMethod" RequiredField-IsRequired="true" RequiredField-ErrorText="Vælg startdato for periode" SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip">
                        <RequiredField IsRequired="True" ErrorText="V&#230;lg startdato for periode"></RequiredField>
                    </ValidationSettings>
                </dx:ASPxDateEdit>
            </td>
            <td style="width:150px">
                <dx:ASPxDateEdit ID="txtEnddate" ClientInstanceName="txtEnddate" runat="server">
                    <ValidationSettings CausesValidation="true" ValidationGroup="SelectMethod" RequiredField-IsRequired="true" RequiredField-ErrorText="Vælg slutdato for periode" SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip">
                        <RequiredField IsRequired="True" ErrorText="V&#230;lg slutdato for periode"></RequiredField>
                    </ValidationSettings>
                </dx:ASPxDateEdit>
            </td>
            <td style="width:150px">
                <dx:ASPxComboBox ID="ddlMethod" ClientInstanceName="ddlMethod" runat="server" Width="150px">
                    <Items>
                        <dx:ListEditItem Selected="true" Value="-1" Text="Alle kunder" />
                    </Items>
                </dx:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dx:ASPxButton ID="btnSubmitMethod" runat="server" Text="Vis liste" AutoPostBack="False" UseSubmitBehavior="False" Width="75px">
                    <ClientSideEvents Click="function(s, e) { MethodClicked(); }" />
                </dx:ASPxButton>
            </td>
            <td style="width:150px">
                <dx:ASPxComboBox ID="ddlEmailCount" ClientInstanceName="ddlEmailCount" runat="server" Width="150px">
                    <Items>
                        <dx:ListEditItem Value="10" Text="Send 10" />
                        <dx:ListEditItem Value="20" Selected="true" Text="Send 20" />
                        <dx:ListEditItem Value="40" Text="Send 40" />
                    </Items>
                </dx:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dx:ASPxButton ID="btnSendBookingLinkEmail" runat="server" Text="Send emails" AutoPostBack="False" UseSubmitBehavior="False" Width="75px">
                    <ClientSideEvents Click="function(s, e) { SendBookingLinkEmail(); }" />
                </dx:ASPxButton>
            </td>
            <td align="right">
                <asp:Label ID="lblView" runat="server" Text="Visning"></asp:Label>
                <asp:Label ID="lblPageSize" runat="server" Text="Antal linjer pr side"></asp:Label>
                <asp:DropDownList ID="ddlPageSize" runat="server" AutoPostBack="true">
                    <asp:ListItem Value="10">10</asp:ListItem>
                    <asp:ListItem Value="25">25</asp:ListItem>
                    <asp:ListItem Value="50">50</asp:ListItem>
                    <asp:ListItem Value="100">100</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
    </table>          
    <hr />
    
    <dx:ASPxGridView ID="gvCustomer" runat="server" ClientInstanceName="gvCustomer" OnCustomCallback="gvCustomer_CustomCallback" 
        KeyFieldName="CustomerId" Width="100%" AutoGenerateColumns="False" EnableCallBacks="True">
        <SettingsLoadingPanel Text="Henter&amp;hellip;" />
        <Settings ShowHeaderFilterButton="true" ShowGroupPanel="true" ShowFilterRow="True" />
        <SettingsPager AlwaysShowPager="True" PageSize="25" Position="TopAndBottom">
            <Summary 
                AllPagesText="Sider: {0} - {1} ({2} kunder)" 
                Text="Side {0} af {1} ({2} kunder)" />
        </SettingsPager>
        <SettingsText ConfirmDelete="Vil du slette denne kunde?" GroupPanel="Træk kolonne hertil for at gruppere efter den" HeaderFilterShowAll="Vis alle" />
        <SettingsBehavior ConfirmDelete="True" AllowGroup="true" AllowDragDrop="true" />
                            
        <Columns>
            <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0">
                    <HeaderTemplate>
                        <input type="checkbox" onclick="gvCustomer.SelectAllRowsOnPage(this.checked);" style="vertical-align:middle;" title="Vælg/Fravælg alle linjer på siden"></input>
                    </HeaderTemplate>
                    <HeaderStyle Paddings-PaddingTop="1" Paddings-PaddingBottom="1" 
                        HorizontalAlign="Center">
                    <Paddings PaddingTop="1px" PaddingBottom="1px"></Paddings>
                    </HeaderStyle>
            </dx:GridViewCommandColumn>
            <dx:GridViewDataHyperLinkColumn FieldName="CustomerId" VisibleIndex="0" Caption="Kundenr">
                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/View/CustomerView/EditCustomerData.aspx?CustomerId={0}" TextField="CustomerId">
                </PropertiesHyperLinkEdit>
            </dx:GridViewDataHyperLinkColumn>
            <dx:GridViewDataHyperLinkColumn FieldName="ParentCustomerId" VisibleIndex="2" Caption="Afdeling">
                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/View/CustomerView/EditCustomerData.aspx?CustomerId={0}" TextField="CompanyName">
                </PropertiesHyperLinkEdit>
            </dx:GridViewDataHyperLinkColumn>
            <dx:GridViewDataColumn FieldName="CompanyName" VisibleIndex="3" Caption="Firma">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="Name" VisibleIndex="3" Caption="Navn">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="Address" VisibleIndex="4" Caption="Adresse">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="ZipCode" VisibleIndex="5" Caption="Postnr">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="City" VisibleIndex="6" Caption="By">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="SecondaryAddress" VisibleIndex="12" Caption="Sek.Adresse">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="SecondaryZipCode" VisibleIndex="13" Caption="Sek.Postnr">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="SecondaryCity" VisibleIndex="14" Caption="Sek.By">
            </dx:GridViewDataColumn>
        </Columns>
                            
    </dx:ASPxGridView>

</asp:Content>
